package b.d;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.hardware.biometrics.BiometricPrompt;
import android.hardware.biometrics.BiometricPrompt.AuthenticationCallback;
import android.hardware.biometrics.BiometricPrompt.AuthenticationResult;
import android.hardware.biometrics.BiometricPrompt.Builder;
import android.hardware.biometrics.BiometricPrompt.CryptoObject;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.biometric.DeviceCredentialHandlerActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import b.l.a.i;
import c.h.a.m0.o;
import java.util.Objects;
import java.util.concurrent.Executor;

@SuppressLint({"SyntheticAccessor"})
/* compiled from: BiometricFragment */
public class a extends Fragment {
    public Context W;
    public Bundle X;
    public Executor Y;
    public OnClickListener Z;
    public androidx.biometric.BiometricPrompt.b b0;
    public androidx.biometric.BiometricPrompt.d c0;
    public CharSequence d0;
    public boolean e0;
    public BiometricPrompt f0;
    public CancellationSignal g0;
    public boolean h0;
    public final Handler i0 = new Handler(Looper.getMainLooper());
    public final Executor j0 = new a();
    public final AuthenticationCallback k0 = new b();
    public final OnClickListener l0 = new c();
    public final OnClickListener m0 = new d();

    /* compiled from: BiometricFragment */
    public class a implements Executor {
        public void execute(Runnable runnable) {
            a.this.i0.post(runnable);
        }
    }

    /* compiled from: BiometricFragment */
    public class b extends AuthenticationCallback {

        /* compiled from: BiometricFragment */
        public class a implements Runnable {
            public final /* synthetic */ CharSequence a;
            public final /* synthetic */ int b;

            public a(CharSequence charSequence, int i) {
                this.a = charSequence;
                this.b = i;
            }

            public void run() {
                Object obj;
                CharSequence charSequence = this.a;
                if (charSequence == null) {
                    StringBuilder stringBuilder = new StringBuilder();
                    c.b.a.a.a.n(a.this.W, 2131689783, stringBuilder, " ");
                    stringBuilder.append(this.b);
                    charSequence = stringBuilder.toString();
                }
                androidx.biometric.BiometricPrompt.b bVar = a.this.b0;
                int i = this.b;
                switch (i) {
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 7:
                    case 8:
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 13:
                    case 14:
                        obj = null;
                        break;
                    default:
                        obj = 1;
                        break;
                }
                if (obj != null) {
                    i = 8;
                }
                bVar.a(i, charSequence);
            }
        }

        /* compiled from: BiometricFragment */
        public class b implements Runnable {
            public final /* synthetic */ androidx.biometric.BiometricPrompt.c a;

            public b(androidx.biometric.BiometricPrompt.c cVar) {
                this.a = cVar;
            }

            public void run() {
                a.this.b0.b(this.a);
            }
        }

        /* compiled from: BiometricFragment */
        public class c implements Runnable {
            public void run() {
                Objects.requireNonNull((c.h.a.j0.z0.c) a.this.b0);
                o.b.a(0);
            }
        }

        public void onAuthenticationError(int i, CharSequence charSequence) {
            if (!j.a()) {
                a.this.Y.execute(new a(charSequence, i));
                a.this.n0();
            }
        }

        public void onAuthenticationFailed() {
            a.this.Y.execute(new c());
        }

        public void onAuthenticationHelp(int i, CharSequence charSequence) {
        }

        public void onAuthenticationSucceeded(AuthenticationResult authenticationResult) {
            androidx.biometric.BiometricPrompt.c cVar;
            androidx.biometric.BiometricPrompt.d dVar = null;
            if (authenticationResult != null) {
                CryptoObject cryptoObject = authenticationResult.getCryptoObject();
                if (cryptoObject != null) {
                    if (cryptoObject.getCipher() != null) {
                        dVar = new androidx.biometric.BiometricPrompt.d(cryptoObject.getCipher());
                    } else if (cryptoObject.getSignature() != null) {
                        dVar = new androidx.biometric.BiometricPrompt.d(cryptoObject.getSignature());
                    } else if (cryptoObject.getMac() != null) {
                        dVar = new androidx.biometric.BiometricPrompt.d(cryptoObject.getMac());
                    }
                }
                cVar = new androidx.biometric.BiometricPrompt.c(dVar);
            } else {
                cVar = new androidx.biometric.BiometricPrompt.c(null);
            }
            a.this.Y.execute(new b(cVar));
            a.this.n0();
        }
    }

    /* compiled from: BiometricFragment */
    public class c implements OnClickListener {
        public void onClick(DialogInterface dialogInterface, int i) {
            a.this.Z.onClick(dialogInterface, i);
        }
    }

    /* compiled from: BiometricFragment */
    public class d implements OnClickListener {
        public void onClick(DialogInterface dialogInterface, int i) {
            if (i == -2) {
                j.c("BiometricFragment", a.this.e(), a.this.X, null);
            }
        }
    }

    /* compiled from: BiometricFragment */
    public class e implements Runnable {
        public void run() {
            a.this.h0 = true;
        }
    }

    public void D(Context context) {
        super.D(context);
        this.W = context;
    }

    public void E(Bundle bundle) {
        super.E(bundle);
        j0(true);
    }

    public View G(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        int i = VERSION.SDK_INT;
        if (!this.e0) {
            Bundle bundle2 = this.X;
            if (bundle2 != null) {
                this.d0 = bundle2.getCharSequence("negative_text");
                Builder builder = new Builder(k());
                builder.setTitle(this.X.getCharSequence("title")).setSubtitle(this.X.getCharSequence("subtitle")).setDescription(this.X.getCharSequence("description"));
                boolean z = this.X.getBoolean("allow_device_credential");
                if (z && i <= 28) {
                    String x = x(2131689760);
                    this.d0 = x;
                    builder.setNegativeButton(x, this.Y, this.m0);
                } else if (!TextUtils.isEmpty(this.d0)) {
                    builder.setNegativeButton(this.d0, this.Y, this.l0);
                }
                if (i >= 29) {
                    builder.setConfirmationRequired(this.X.getBoolean("require_confirmation", true));
                    builder.setDeviceCredentialAllowed(z);
                }
                if (z) {
                    this.h0 = false;
                    this.i0.postDelayed(new e(), 250);
                }
                this.f0 = builder.build();
                CancellationSignal cancellationSignal = new CancellationSignal();
                this.g0 = cancellationSignal;
                androidx.biometric.BiometricPrompt.d dVar = this.c0;
                if (dVar == null) {
                    this.f0.authenticate(cancellationSignal, this.j0, this.k0);
                } else {
                    CryptoObject cryptoObject;
                    BiometricPrompt biometricPrompt = this.f0;
                    if (dVar != null) {
                        if (dVar.b != null) {
                            cryptoObject = new CryptoObject(dVar.b);
                        } else if (dVar.a != null) {
                            cryptoObject = new CryptoObject(dVar.a);
                        } else if (dVar.c != null) {
                            cryptoObject = new CryptoObject(dVar.c);
                        }
                        biometricPrompt.authenticate(cryptoObject, this.g0, this.j0, this.k0);
                    }
                    cryptoObject = null;
                    biometricPrompt.authenticate(cryptoObject, this.g0, this.j0, this.k0);
                }
            }
        }
        this.e0 = true;
        return null;
    }

    public void m0() {
        if (VERSION.SDK_INT >= 29) {
            Bundle bundle = this.X;
            boolean z = false;
            if (bundle != null && bundle.getBoolean("allow_device_credential", false)) {
                z = true;
            }
            if (z && !this.h0) {
                Log.w("BiometricFragment", "Ignoring fast cancel signal");
                return;
            }
        }
        CancellationSignal cancellationSignal = this.g0;
        if (cancellationSignal != null) {
            cancellationSignal.cancel();
        }
        n0();
    }

    public void n0() {
        this.e0 = false;
        FragmentActivity e = e();
        i iVar = this.r;
        if (iVar != null) {
            b.l.a.a aVar = new b.l.a.a(iVar);
            aVar.e(this);
            aVar.k();
        }
        if ((e instanceof DeviceCredentialHandlerActivity) && !e.isFinishing()) {
            e.finish();
        }
    }

    public void o0(Executor executor, OnClickListener onClickListener, androidx.biometric.BiometricPrompt.b bVar) {
        this.Y = executor;
        this.Z = onClickListener;
        this.b0 = bVar;
    }
}
